package cc.monggo.third.client;

import java.util.HashMap;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.params.HttpMethodParams;

public abstract class BaseClient {
	//protected static HttpMethod method = null;
	protected static HttpClient client = new HttpClient();
	
	protected static void init(HashMap<String,String> params){
		//setProxy();
		setCharset();
		setHost(params);
		//setMethod(params);
	}
	
	private static void setProxy(){
		client.getHostConfiguration().setProxy("192.168.16.189", 8080);
		client.getParams().setAuthenticationPreemptive(true);
		UsernamePasswordCredentials creds = new UsernamePasswordCredentials("fangjinsong","fang2012"); 
		client.getState().setProxyCredentials(AuthScope.ANY, creds);	
	}
	
	private static void setCharset(){
		client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"UTF-8");
	}
	
	private static void setHost(HashMap<String,String> params){
		String host 	= params.get("host") + "";
		int port 		= Integer.valueOf(params.get("port") + "");
		String protocol = params.get("protocol") + "";
		client.getHostConfiguration().setHost(host, port, protocol);
	}
	
	/*private static void setMethod(HashMap<String,String> params){
		method.setPath(params.get("path") + "");
	}*/
}
